<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>加减款</title>
	<%@ include file="/view/common/tags.jsp"%>
    <style type="text/css">
        table th{text-align: center}
    </style>
</head>
<body>
	<section class="content">
    	<div class="row">
            <div class="col-md-12">
                <div class="box">
                	<div class="box-body">
						<div class="panel panel-default">
                            <div class="panel-body" style="padding-bottom:5px;">
                                <form class="form-horizontal" action="" method="post" id="saveAndUpdateFrom">
                                    <input type="hidden" id="token" name="token" value="" />
                                    <input type="hidden" id="rowId" name="rowId" value="" />
                                    <input type="hidden" id="moneyWaySmallId" name="moneyWaySmallId" value="" />
                                    <input type="hidden" id="moneyWaySmallName" name="moneyWaySmallName" value="" />
                                    <input type="hidden" id="drawFlag" name="drawFlag" value="" />
                                    <input type="hidden" id="addressFlag" name="addressFlag" value="" />
                                    <input type="hidden" id="feeRate" name="feeRate" value="" />
                                    <input type="hidden" id="minFee" name="minFee" value="" />
                                    <input type="hidden" id="maxFee" name="maxFee" value="" />
                                    <input type="hidden" id="pageData" name="pageData" value="" />
                                </form>
                              	<div class="searchMenu">
                                      <div class="col-xs-10"></div>
                              	</div>
                        	</div>
						</div>
                        <table class="table table-hover table-condensed table-bordered table-striped" id="dataTable">
                            <thead>
                            	<tr>
                                	<th data-field="index" data-align="center" data-formatter="indexFormatter" data-sortable="false" style="width:100px;">序号</th>
                                	<th data-field="moneyWaySmallName" data-align="center">提现银行</th>
                                	<th data-field="drawFlag" data-align="center">是否开通</th>
                                	<th data-field="addressFlag" data-align="center">是否需要支行地址</th>
                                    <th data-field="feeRate" data-align="center">费率</th>
                                    <th data-field="minFee" data-align="center">最低金额</th>
									<th data-field="maxFee" data-align="center">最高金额</th>
									<th data-field="btnField" data-align="center">操作</th>
                                </tr>
                            </thead>
                            <tbody id="tbody" style="text-align: center">
                                <tr data-index='0'>
                                    <td colspan="7">正在获取数据。。。</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
       	</div>
	</section>
   <%@ include file="/view/common/footer.jsp"%>
</body>
<script>
// 提示信息
var msgg='<%=request.getAttribute("msg")%>';
if (msgg && msgg!=null && msgg!='null') { 
	  layer.msg(msgg);
}
var tableIndex = 0; // 添加修改的弹出框的ID
var finDrawStateDictList = "" // 订单状态字典数据
var finDrawWayDictList = "" // 提现方式字典数据

$(function(){
    $("#token").val(sessionStorage.getItem("token"));
    $("#token2").val(sessionStorage.getItem("token"));
    
    // 加载table 数据
    $.ajax({
        url: "${fundCenterV1}/fundFinanceDrawWayConfig/data.json",
        type: "post",
        cache: false,
        data: {"gameId":$("#gameId").val(), token: sessionStorage.getItem("token")},
        dataType:"json",
        async:false,
        success: function(data) {
            initPageData(data);
        }
    });
})

function initPageData(exchangeWayAll){
    var html = "";
    var drawFlagTD = "<td></td>";
    var addressFlagTD = "<td></td>";
    
    var index = 0;
    for(var i in exchangeWayAll){
        index = Number(i) + 1;
        drawFlagTD = "<td><input type='checkbox' id='drawFlag" + index + "' name='drawFlag' value='1' checked='checked'/></td>";
        addressFlagTD = "<td><input type='checkbox' id='addressFlag" + index + "' name='addressFlag' value='1' checked='checked'/></td>";
        
        html += "<tr data-index='" + index + "'>";
        html += "<td>" + index + "</td>";
        html += "<td><span id='wayNameSpan'>" + exchangeWayAll[i].moneyWaySmallName + "</span>";
        html += "    <input type='hidden' id='rowId" + index + "' name='rowId' value='" + exchangeWayAll[i].rowId + "'/>";
        html += "    <input type='hidden' id='moneyWaySmallId" + index + "' name='moneyWaySmallId' value='" + exchangeWayAll[i].moneyWaySmallId + "'/>";
        html += "    <input type='hidden' id='moneyWaySmallName" + index + "' name='moneyWaySmallName' value='" + exchangeWayAll[i].moneyWaySmallName + "'/>";
        html += "</td>";
        if(exchangeWayAll[i].drawFlag == 0){
        	drawFlagTD = "<td><input type='checkbox' id='drawFlag" + index + "' name='drawFlag' value='0'/></td>";
        }
        if(exchangeWayAll[i].addressFlag == 0){
        	addressFlagTD = "<td><input type='checkbox' id='addressFlag" + index + "' name='addressFlag' value='0'/></td>";
        }
        html += drawFlagTD;
        html += addressFlagTD;
        html += "<td><input type='text' id='feeRate" + index + "' name='feeRate' class='form-control' style='width:100px;' value='" + parseFloat(exchangeWayAll[i].feeRate).toFixed(5) + "'/></td>";
        html += "<td><input type='text' id='minFee" + index + "' name='minFee' class='form-control' style='width:100px;' value='" + parseFloat(exchangeWayAll[i].minFee).toFixed(2) + "'/></td>";
        html += "<td><input type='text' id='maxFee" + index + "' name='maxFee' class='form-control' style='width:100px;' value='" + parseFloat(exchangeWayAll[i].maxFee).toFixed(2) + "'/></td>";
        html += "<td><input type='button' class='btn btn-primary btn-sm' value='保 存' onclick='svaeWay(" + index + ")'/></td>";
        html += "</tr>";
    }
    $("#tbody").html(html);
}

function svaeWay(index){
	var feeRate = $("#feeRate" + index).val();
	if(!CheckUtil.isFloat(feeRate, "+") && !CheckUtil.isInt(feeRate, "+")){
        layer.msg("请填写正确的费率！");
        $("#feeRate" + index).focus();
        return false;
    }
	
	var minFee = $("#minFee" + index).val();
	if(!CheckUtil.isFloat(minFee, "+") && !CheckUtil.isInt(minFee, "+")){
        layer.msg("请填写正确的最小金额！");
        $("#minFee" + index).focus();
        return false;
    }
	
	var maxFee = $("#maxFee" + index).val();
	if(!CheckUtil.isFloat(maxFee, "+") && !CheckUtil.isInt(maxFee, "+")){
        layer.msg("请填写正确的最大金额！");
        $("#maxFee" + index).focus();
        return false;
    }
	
	var drawFlag = $("#drawFlag" + index).is(":checked") ? 1 : 0;
	var addressFlag = $("#addressFlag" + index).is(":checked") ? 1 : 0;
	
	$("#rowId").val($("#rowId" + index).val());
	$("#moneyWaySmallId").val($("#moneyWaySmallId" + index).val());
	$("#moneyWaySmallName").val($("#moneyWaySmallName" + index).val());
	$("#drawFlag").val(drawFlag);
	$("#addressFlag").val(addressFlag);
	$("#feeRate").val(feeRate);
	$("#minFee").val(minFee);
	$("#maxFee").val(maxFee); 
    
	$.ajax({
        url: "${fundCenterV1}/fundFinanceDrawWayConfig/saveFundFinanceDrawWayConfig",
        type: "post",
        cache: false,
        data: new FormData($("#saveAndUpdateFrom")[0]),
        dataType:"json",
        processData: false,
        contentType: false,
        async:false,
        success: function(data) {
            if(data.code == 0){
                parent.layer.msg("修改成功！");
            } else if(data.code == "-2"){
                parent.window.location.href="${sysManagerV1}/";
            } else {
                parent.layer.msg(data.message);
            }
        }
    });
    
}

// 行点击事件
$(function(){
     $("body").on("click","table>tbody>tr",function(){
      $(this).css("background","#e1ecf1").siblings().css("background","");
   });
})

</script>
</html>